/**
 * 版权所有（c）2021. 上海海鼎信息工程股份有限公司，保留所有权利
 */
package com.lovely602.design.structure.flyweight.demo;

import java.util.ArrayList;

/**
 * 享元工厂角色
 *
 * @author lizhixing
 */
public class WeiqiFactory {

  private ArrayList<ChessPieces> qz;

  public WeiqiFactory() {
    qz = new ArrayList<ChessPieces>();
    ChessPieces w = new WhitePieces();
    qz.add(w);
    ChessPieces b = new BlackPieces();
    qz.add(b);
  }

  public ChessPieces getChessPieces(String type) {
    if (type.equalsIgnoreCase("w")) {
      return (ChessPieces) qz.get(0);
    } else if (type.equalsIgnoreCase("b")) {
      return (ChessPieces) qz.get(1);
    } else {
      return null;
    }
  }

}
